﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LX.Cache;
using LX.Core.Auth;
using LX.Data;
using LX.IO;
using LX.Log;

namespace LX.Core.Data
{
    public class ApplicationTransaction:IDisposable
    {
        private ILog _logger;
        private IAuthorizeManager _authorizeManager;
        private IPrincipal _currentPrincipal;
        private IPersistentContext _repository;

        /// <summary>
        /// 日志记录器
        /// </summary>
        public ILog Logger
        {
            get { return _logger; }
            set { _logger = value; }
        }

        /// <summary>
        /// 授权管理器
        /// </summary>
        public IAuthorizeManager AuthorizeManager
        {
            get { return _authorizeManager; }
            set { _authorizeManager = value; }
        }

        /// <summary>
        /// 当前安全主体
        /// </summary>
        public IPrincipal CurrentPrincipal
        {
            get { return _currentPrincipal; }
            set { _currentPrincipal = value; }
        }

        /// <summary>
        /// 数据持久化器
        /// </summary>
        public IPersistentContext Repository
        {
            get { return _repository; }
            set { _repository = value; }
        }


        public IDistributionFileManager FileManager { get; set; }

        /// <summary>
        /// 缓存管理器
        /// </summary>
        public ICacheProvider CacheProvider { get; set; }

        public void Dispose()
        {
            if(this.Repository!=null)
            {
                this.Repository.Commit();
            }
        }
    }
}
